package com.qf.android.huihui.presenter;

import android.content.Context;
import android.util.Log;

import com.qf.android.huihui.bean.DetailListBean;
import com.qf.android.huihui.model.DetailListModel;
import com.qf.android.huihui.model.impl.IDetailList;
import com.qf.android.huihui.presenter.impl.BasePresenter;
import com.qf.android.huihui.view.fragment.impl.IDetailListView;

import java.util.ArrayList;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by lx on 2017/1/6.
 */

public class DetailListPresenter implements BasePresenter {
    private IDetailList model;
    private IDetailListView view;
    private Context context;
    private ArrayList<DetailListBean> list;
    public DetailListPresenter(IDetailListView view, Context context) {
        this.view = view;
        this.context = context;
        model = new DetailListModel();
    }



    @Override
    public void getData() {
        final Observable<DetailListBean> detailList =model.loadInfo();
        detailList.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<DetailListBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(DetailListBean detailListBean) {
                        Log.e("aa",detailListBean.toString());
                        view.setDate(detailListBean);
                    }
                });
    }

    @Override
    public void getData(Object page, Object type, boolean isUpfresh, boolean isDownfresh, Object adapter, Object recyclerview) {

    }

    @Override
    public void getData(Object adapter, Object recyclerview) {

    }


    //@Override
    //   public void getStr(String str) {
    //                try {
//                    JSONObject js=new JSONObject(response);
//                    JSONArray jsa=js.getJSONArray("data");
//                    for (int i = 0; i < jsa.length(); i++) {
//                        DetailListBean bean=new DetailListBean();
//                        bean.parseJson(jsa.getJSONObject(i));
//                        lists.add(bean);
//                        Log.e("TS",bean.getImage_url());
//                    }
//
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//    view.setDate(str);
//    Log.e("TS",str);
//}
}
